Add build_sam3_multiplex_tracking and Sam3VideoPredictor multiplex routing - #600
Add build_sam3_multiplex_tracking and Sam3VideoPredictor multiplex routing#600johnwbrisbin wants to merge 1 commit into
Conversation
Adds three related capabilities needed for single-image inference with the SAM 3.1 multiplex checkpoint: 1. build_sam3_multiplex_tracking(): new public builder that assembles Sam3MultiplexTrackingWithInteractivity without the video-predictor wrapper. Exposes .detector (Sam3MultiplexDetector) for use with Sam3Processor-based image inference. Includes FA3 auto-detection (imports flash_attn_interface, falls back to use_fa3=False if absent). 2. Sam3VideoPredictor routing: when checkpoint_path contains "multiplex", __init__ now calls build_sam3_multiplex_tracking instead of build_sam3_video_model, which was incompatible with the multiplex checkpoint architecture (different tensor shapes in maskmem_backbone). Adds enable_inst_interactivity parameter (no-op; instance interactivity is always enabled in the multiplex architecture). 3. decoder.py forward_ffn: cast tgt to the weight dtype before the autocast-disabled region. Prevents dtype mismatches when torch.compile emits bf16 kernels (observed on CUDA 13 / Blackwell) while the activation tensor is still fp32 from an outer autocast context. 4. sam3/__init__.py: export Sam3VideoPredictor and Sam3Processor so callers can import them directly from the top-level package.
|
Hi @johnwbrisbin! Thank you for your pull request and welcome to our community. Action RequiredIn order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you. ProcessIn order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA. Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks! |
|
Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks! |
Summary
Adds three capabilities needed for single-image inference with the SAM 3.1 multiplex checkpoint:
build_sam3_multiplex_tracking()— new public builder that assemblesSam3MultiplexTrackingWithInteractivitywithout the video-predictor wrapper. Exposes.detector(Sam3MultiplexDetector) for use withSam3Processor-based image inference. Includes FA3 auto-detection (importsflash_attn_interface, falls back touse_fa3=Falseif absent).Sam3VideoPredictormultiplex routing — whencheckpoint_pathcontains"multiplex",__init__now callsbuild_sam3_multiplex_trackinginstead ofbuild_sam3_video_model, which was incompatible with the multiplex checkpoint architecture (different tensor shapes inmaskmem_backbone). Addsenable_inst_interactivityparameter (instance interactivity is always enabled in the multiplex architecture).decoder.py forward_ffndtype fix — caststgtto the weight dtype before the autocast-disabled region, preventing dtype mismatches whentorch.compileemits bf16 kernels (observed on CUDA 13 / Blackwell).sam3/__init__.py— exportsSam3VideoPredictorandSam3Processorfrom the top-level package.Motivation
Sam3VideoPredictorloaded withsam3.1_multiplex_fp16.safetensorscrashed with size mismatches because the multiplex checkpoint uses a differentmaskmem_backbonearchitecture than the non-multiplex model built bybuild_sam3_video_model.build_sam3_multiplex_trackingbuilds the correct architecture and loads the full checkpoint (tracker + detector) in one pass.Test plan
sam3.1_multiplex_fp16.safetensorsviaSam3VideoPredictor— previously crashed with size mismatch, now loads the multiplex architecture correctlySam3VideoPredictorwith a SAM 3 (non-multiplex) checkpoint still routes tobuild_sam3_video_modelunchangedbuild_sam3_multiplex_tracking()returns a model with.detectoraccessible toSam3Processorforward_ffn